package models

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Mobile   string `gorm:"type:varchar(30);comment:'账号'"`
	Password string `gorm:"type:char(32);comment:'密码'"`
	Status   int64  `gorm:"type:varchar(20);default:'正常';comment:'用户状态 1正常、2已正常发布房源、3冻结、4注销'"`
}

func (u *User) GetUserByMobile() error {
	return DB.Where("mobile=?", u.Mobile).Limit(1).Find(&u).Error
}

func (u *User) Register() error {
	return DB.Create(&u).Error
}

func (u *User) GetUserById() error {
	return DB.Where("id=?", u.ID).Limit(1).Find(&u).Error
}

type RealName struct {
	gorm.Model
	RealName string
	IdCard   string
	UserId   int64
}

func (r *RealName) GetRealNameByUserId() error {
	return DB.Where("user_id=?", r.UserId).Limit(1).Find(&r).Error
}

func (r *RealName) CreateRealName() error {
	return DB.Create(&r).Error
}

func (r *RealName) Update() error {
	return DB.Updates(&r).Error
}
